/*
	Title: 01_Figure3.do
	Paper: Brauning, Ivashina, Ozdagli (2025)
	Description: Figure 3 - Earning, debt, and covenant violations around COVID-19 crisis
*/

/*------------------------------------------------------------------------------
								  Figure 3	
------------------------------------------------------------------------------*/
// Import Figure 3 data 
use "$data_path/Figure3.dta", clear 
set scheme s1color

// Label variables
label var either_violation   	 "Share of firms in covenant violation"
label var Iin_covenant_violation "Share of firms in incurrence covenant violation"
label var in_covenant_violation	 "Share of firms in maintenance covenant violation"

format qdate %tqCY!Qq

// Create Either Covenant Violation Figure
twoway (line oibdpq qdate, lcolor(blue)) ///
	   (line debt qdate, lcolor(orange)) ///
	   (area either_violation qdate, sort yaxis(2) fcolor(gs12%50) lwidth(none)), ///
		legend(order( 1 "EBITDA" 2 "Debt" 3 "Covenant violations" ) rows(1) region(lcolor(white))) ///
		ytitle("2019Q4 = 1") xtitle("") graphregion(color(white)) /// 
		name(Figure3_Either, replace)
		
graph export "$figures_path/Figure3_Either.png", replace 


// Create Incurrence Only Figure
twoway (line oibdpq qdate, lcolor(blue)) ///
	   (line debt qdate, lcolor(orange)) ///
	   (area Iin_covenant_violation qdate, sort yaxis(2) fcolor(gs12%50) lwidth(none)), ///
		legend(order( 1 "EBITDA" 2 "Debt" 3 "Covenant violations" ) rows(1) region(lcolor(white))) ///
		ytitle("2019Q4 = 1") xtitle("") graphregion(color(white)) /// 
		name(Figure3_Incurrence, replace)

graph export "$figures_path/Figure3_Incurrence.png", replace 


// Create Maintenance Only Figure
twoway (line oibdpq qdate, lcolor(blue)) ///
	   (line debt qdate, lcolor(orange)) ///
	   (area in_covenant_violation qdate, sort yaxis(2) fcolor(gs12%50) lwidth(none)), ///
		legend(order( 1 "EBITDA" 2 "Debt" 3 "Covenant violations" ) rows(1) region(lcolor(white))) ///
		ytitle("2019Q4 = 1") xtitle("") graphregion(color(white)) /// 
		name(Figure3_Maintenance, replace)
		
graph export "$figures_path/Figure3_Maintenance.png", replace 		